﻿@page "/Products/Add"
@page "/Products/{productId:int}/Edit"
@using Microsoft.AspNetCore.Authorization
@using maERP.SharedUI.Pages.Products.Components

@attribute [Authorize]

@* ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract *@
@if (product == null)
{
    <p><em>Lade...</em></p>
}
else
{
    <MudText Typo="Typo.h4" Class="mb-8">Produkt bearbeiten</MudText>

    <MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenProductAiHelper">AI Assist</MudButton>
    
    <MudOverlay @bind-Visible="productAiHelperVisible" DarkBackground="true" AutoClose="false" Class="pt-8 white">
        <ProductAiHelper />
    </MudOverlay>
    
    <MudForm Model="@product" @ref="@_form">
        <MudGrid>
            <MudItem xs="6">
                <MudTextField @bind-Value="product.Name"
                              For="@(() => product.Name)"
                              Label="Name"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="true"
                              Class="mt-6" />

                <MudTextField @bind-Value="product.Sku"
                              For="@(() => product.Sku)"
                              Label="SKU"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="true"
                              Class="mt-6" />

                <MudTextField @bind-Value="product.Ean"
                              For="@(() => product.Ean)"
                              Label="EAN"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="false"
                              Class="mt-6" />

                <MudTextField @bind-Value="product.Price"
                              For="@(() => product.Price)"
                              Label="Preis in EUR"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="false"
                              Class="mt-6" />

                <MudTextField @bind-Value="product.Msrp"
                              For="@(() => product.Msrp)"
                              Label="UVP in EUR"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="false"
                              Class="mt-6" />

                <MudTextField @bind-Value="product.Description"
                              For="@(() => product.Description)"
                              Label="Beschreibung"
                              Variant="Variant.Text"
                              InputType="InputType.Text"
                              Required="false"
                              Class="mt-6" />

                <MudButton Variant="Variant.Filled"
                           Color="Color.Primary"
                           Size="Size.Large"
                           ButtonType="ButtonType.Button"
                           OnClick="@(Save)"
                           Class="mt-6">Speichern</MudButton>
            </MudItem>
        </MudGrid>
    </MudForm>
}

